import { Exclude } from 'class-transformer'
import {
  Column,
  Entity,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToMany,
} from 'typeorm'
import { Role } from '../role/role.entity'

export enum UserRoles {
  super = 'seper',
  admin = 'admin',
  editor = 'editor',
  test = 'test',
}

@Entity('users')
export class User {
  @PrimaryGeneratedColumn()
  id: number

  @Column({ nullable: true, length: 32, comment: '用户显示昵称' })
  public nickname: string

  @Column()
  username: string

  @Exclude({ toPlainOnly: true }) // 输出屏蔽密码
  @Column({
    nullable: true,
    length: 200,
    comment: '用户登录密码',
    type: 'varchar',
  })
  public password: string

  @Column({ nullable: true, length: 20, comment: '用户手机号码', unique: true })
  public mobile: string

  @ManyToMany(() => Role, (role) => role.users)
  roles: Role[]

  @CreateDateColumn({
    type: 'timestamp',
    name: 'create_date',
    comment: '创建时间',
  })
  createDate: Date

  @UpdateDateColumn({
    type: 'timestamp',
    name: 'update_date',
    comment: '更新时间',
  })
  updateDate: Date

  @Column({ type: 'boolean', comment: '状态1正常0禁用', default: true })
  public status: boolean
}
